home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Imágenes y mapas de bits / DrawOnPixelSizeImage / DrawOnPixelSizeImage.cs next >
Encoding:
Text File  |  2002-05-06  |  1.1 KB  |  41 lines

  1. //---------------------------------------------------
  2. // DrawOnPixelSizeImage.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class DrawOnPixelSizeImage: PrintableForm
  9. {
  10.     Image  image;
  11.     string str = "Apollo11";
  12.  
  13.     public new static void Main()
  14.     {
  15.         Application.Run(new DrawOnPixelSizeImage());
  16.     }
  17.     public DrawOnPixelSizeImage()
  18.     {
  19.         Text  = "Dibujar sobre una imagen en pφxeles";
  20.         image = Image.FromFile("..\\..\\..\\Apollo11FullColor.jpg");
  21.  
  22.         Graphics grfxImage  = Graphics.FromImage(image);
  23.         Graphics grfxScreen = CreateGraphics();
  24.  
  25.         Font font = new Font(Font.FontFamily, 
  26.             grfxScreen.DpiY / grfxImage.DpiY * Font.SizeInPoints);
  27.  
  28.         SizeF sizef = grfxImage.MeasureString(str, font);
  29.  
  30.         grfxImage.DrawString(str, font, Brushes.White, 
  31.             image.Width - sizef.Width, 0);
  32.         grfxImage.Dispose();
  33.         grfxScreen.Dispose();
  34.     }
  35.     protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  36.     {
  37.         grfx.DrawImage(image, 0, 0, image.Width, image.Height);
  38.         grfx.DrawString(str, Font, new SolidBrush(clr), image.Width, 0);
  39.     }
  40. }
  41.